/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.actions.marca;

import com.mapping.Marca;
import com.opensymphony.xwork2.ActionSupport;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.Result;

/**
 *
 * @author PARDmx
 */
@Namespace(value = "/")
@Action(value = "altaMarcaP", results = {
@Result(name = "success", location = "/GestionMarcas/resultadoMarca.jsp")})
public class AltaMarcaAction extends ActionSupport{
    private Marca marca;
    private String Nmarca;
    private String mensaje = "La marca se ha creado satisfactoriamente";

    @Override
    public String execute() throws Exception {
        EntityManagerFactory emf = Persistence.createEntityManagerFactory("inventarios");
        EntityManager em = emf.createEntityManager();
        EntityTransaction tx = em.getTransaction();
        tx.begin();
        marca = new Marca();
        marca.setMarca(Nmarca);                  
        em.persist(marca);        
        em.flush();
        tx.commit();
        em.close();        
        return SUCCESS;        
    }

    public Marca getMarca() {
        return marca;
    }

    public String getMensaje() {
        return mensaje;
    }

    public void setNmarca(String Nmarca) {
        this.Nmarca = Nmarca;
    }
        
}
